﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Nirvana
{
    /// <summary>
    /// 用于根据所有Variable的值，做并行、选择值判断，来作切换图形颜色，阴影，描边等
    /// 需要变化的对象，直接绑定variable变量值，而不需要通过脚本控制。
    /// </summary>
    [RequireComponent(typeof(Graphic))]
    [AddComponentMenu("Nirvana/UI/Bind/Variable Bind Color")]
    public sealed class UIVariableBindColor : UIVariableBindBool
    {
        [HideInInspector]
        [SerializeField]
        private Color enabledColor = Color.white;

        [HideInInspector]
        [SerializeField]
        private Color disabledColor = Color.gray;
        private Graphic graphic;
        private Shadow shadow;
        private Outline outline;
        private UIOuterBevel uiOuterBevel;

        private Color color;

        protected override void OnValueChanged()
        {
            if (graphic == null) graphic = GetComponent<Graphic>();
            if (shadow == null) shadow = GetComponent<Shadow>();
            if (shadow != null) color = shadow.effectColor;
            bool result = base.GetResult();
            if (result)
            {
                graphic.color = this.enabledColor;
                if (shadow != null) shadow.effectColor = color;
            }
            else
            {
                graphic.color = this.disabledColor;
                if (shadow != null) shadow.effectColor = disabledColor;
            }
        }
    }
}

